package com.fenghongzhang.day005;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;

public class MainActivity extends AppCompatActivity {
    private EditText input;
    private Button send;
    private FrameLayout fl;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



        input = (EditText) findViewById(R.id.input);
        send = (Button) findViewById(R.id.send);
        fl = (FrameLayout) findViewById(R.id.fl);

        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = manager.beginTransaction();
        fragmentTransaction.add(R.id.fl,new ContentFragment());
        fragmentTransaction.commit();


    }

    public void send(View view) {
        String s = input.getText().toString();

        ContentFragment contentFragment = new ContentFragment();
        Bundle bundle = new Bundle();
        bundle.putString("name",s);
        contentFragment.setArguments(bundle);
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = manager.beginTransaction();
        //替换
        fragmentTransaction.replace(R.id.fl,contentFragment);
        fragmentTransaction.commit();

    }
}
